package com.modern.devtools.model;

import javafx.beans.property.*;
import javafx.collections.FXCollections;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * Represents a deployment profile with configuration for deploying applications.
 */
public class DeploymentProfile {
    
    private final StringProperty id = new SimpleStringProperty();
    private final StringProperty name = new SimpleStringProperty();
    private final StringProperty description = new SimpleStringProperty();
    private final StringProperty targetPath = new SimpleStringProperty();
    private final StringProperty buildCommand = new SimpleStringProperty();
    private final StringProperty deployScript = new SimpleStringProperty();
    private final ListProperty<String> targetServers = new SimpleListProperty<>();
    private final ObjectProperty<LocalDateTime> lastDeployed = new SimpleObjectProperty<>();
    private final StringProperty status = new SimpleStringProperty("READY"); // READY, IN_PROGRESS, FAILED, SUCCESS
    
    // Constructor
    public DeploymentProfile(String id, String name, String targetPath) {
        setId(id);
        setName(name);
        setTargetPath(targetPath);
    }
    
    // Getters and Setters
    public String getId() {
        return id.get();
    }
    
    public void setId(String id) {
        this.id.set(id);
    }
    
    public StringProperty idProperty() {
        return id;
    }
    
    public String getName() {
        return name.get();
    }
    
    public void setName(String name) {
        this.name.set(name);
    }
    
    public StringProperty nameProperty() {
        return name;
    }
    
    public String getDescription() {
        return description.get();
    }
    
    public void setDescription(String description) {
        this.description.set(description);
    }
    
    public StringProperty descriptionProperty() {
        return description;
    }
    
    public String getTargetPath() {
        return targetPath.get();
    }
    
    public void setTargetPath(String targetPath) {
        this.targetPath.set(targetPath);
    }
    
    public StringProperty targetPathProperty() {
        return targetPath;
    }
    
    public String getBuildCommand() {
        return buildCommand.get();
    }
    
    public void setBuildCommand(String buildCommand) {
        this.buildCommand.set(buildCommand);
    }
    
    public StringProperty buildCommandProperty() {
        return buildCommand;
    }
    
    public String getDeployScript() {
        return deployScript.get();
    }
    
    public void setDeployScript(String deployScript) {
        this.deployScript.set(deployScript);
    }
    
    public StringProperty deployScriptProperty() {
        return deployScript;
    }
    
    public List<String> getTargetServers() {
        return targetServers.get();
    }
    
    public void setTargetServers(List<String> targetServers) {
        this.targetServers.set(FXCollections.observableArrayList(targetServers));
    }
    
    public ListProperty<String> targetServersProperty() {
        return targetServers;
    }
    
    public LocalDateTime getLastDeployed() {
        return lastDeployed.get();
    }
    
    public void setLastDeployed(LocalDateTime lastDeployed) {
        this.lastDeployed.set(lastDeployed);
    }
    
    public ObjectProperty<LocalDateTime> lastDeployedProperty() {
        return lastDeployed;
    }
    
    public String getStatus() {
        return status.get();
    }
    
    public void setStatus(String status) {
        this.status.set(status);
    }
    
    public StringProperty statusProperty() {
        return status;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DeploymentProfile that = (DeploymentProfile) o;
        return Objects.equals(id.get(), that.id.get());
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(id.get());
    }
    
    @Override
    public String toString() {
        return "DeploymentProfile{" +
                "id='" + id.get() + '\'' +
                ", name='" + name.get() + '\'' +
                ", targetPath='" + targetPath.get() + '\'' +
                ", status='" + status.get() + '\'' +
                '}';
    }
}